#include <vector>
#include<stdio.h>
#include"Generation.h"
using namespace std;
   Generation::Generation(long a,long c,long m, long Xo,int iNombreDesValeurs){
        this->a=a;
        this->c=c;
        this->m=m;
        this->Xo=Xo;
        this->iNombreDesValeurs=iNombreDesValeurs;
    }
   vector<double> Generation::process(){
       long X;
       vector<double> vecValeurs;
       for(int i=0;i<iNombreDesValeurs;i++){
           X=(a*Xo+c)%m;
           vecValeurs.push_back((double)X/m);
           Xo=X;
           //printf("\n%d",X);
       }
       return vecValeurs;
   }
   long Generation::getNombreDesValeurs(){
            return iNombreDesValeurs;
        }
    vector<double> Generation::creerDistributionExponentielle(vector<double> vecUniform, double Lamda){
        vector<double> vecDistributionExponentielle;
        double dTemps;
        for(int i=0;i<vecUniform.size();i++){
            if(vecUniform[i]!=0){
            dTemps=-1*log(vecUniform[i])/Lamda;
            vecDistributionExponentielle.push_back(dTemps);
            }
        }
        return vecDistributionExponentielle;
        
    }
    vector<double> Generation::creerDistributionExponentielleRejet(){
            vector<double> vecTemp;
            double x,y,fx,Lamda=0.0001;
            Generation *objGenerationX=new Generation(a,c,m,Xo,1);
            Generation *objGenerationY=new Generation(1029,0,262144,11,1);
            int i=0;
            while(i<iNombreDesValeurs){
            do
            {
            x=m*objGenerationX->process()[0];
            y=Lamda*objGenerationY->process()[0];
            fx=Lamda*exp(-(Lamda*x));
            } while(fx<y);
                vecTemp.push_back(x);
            i++;
            }
            return vecTemp;

        }
